<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>定时器</title>
</head>
<body>
    <h1>0</h1>
    <script>
        let h = document.querySelector("h1");
        let count = 0;
        // 开启定时器
        setInterval(f,100);
        function f(){
            count++;
            h.innerText = count;
        }
        // 开启定时器使用匿名方法
        let timer= setInterval(function(){
            console.log(count)
            if(count>=50){
                // 关闭计时器
                clearInterval(timer)
            }
        },1000)

        // 开启执行一次的定时器
        setTimeout(function(){
            alert("时间到")
        },3000)
    </script>
</body>
</html>